<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        .box{
            width: 790px;
            height: 340px;
            position: relative;
            margin: 100px auto;
        }
        ul {
            position: relative;
            width: 790px;
            height: 340px;
        }
        ul li {
            position: absolute;
            left: 0;
            top: 0;
            /* display:none; */
            opacity: 0;
        }
        .arr {
            display: none;
        }
        .left {
            position: absolute;
            left: 10px;
            top: 35%;
        }
        .right {
            position: absolute;
            right: 10px;
            top: 35%;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul>
            <li style='opacity: 1;'><img src="images/1.jpg" alt=""></li>
            <li><img src="images/2.jpg" alt=""></li>
            <li><img src="images/3.jpg" alt=""></li>
            <li><img src="images/4.jpg" alt=""></li>
            <li><img src="images/5.jpg" alt=""></li>
            <li><img src="images/6.jpg" alt=""></li>
            <li><img src="images/7.jpg" alt=""></li>
        </ul>
        <div class="arr">
            <div class="left"><img src="images/prev.png" alt=""></div>
            <div class="right"><img src="images/next.png" alt=""></div>
        </div>
    </div>
</body>
<script src='../common.js'></script>
<script>
    ;(function(window){
        //获取元素
        var box = document.querySelector('.box')
        var left = document.querySelector('.left')
        var right = document.querySelector('.right')
        var arr = document.querySelector('.arr')
        var liList = document.querySelectorAll('.box li')

        //注册事件
        //移入box出现左右箭头
        box.addEventListener('mouseenter',function(){
            arr.style.display = 'block'
        },false)
        //移出box.左右箭头消失
        box.onmouseleave = function(){
            arr.style.display = ''
        }
        //点击右箭头,切换画面
        var index = 0; //记录当前是第几张
        right.onclick = function(){
            index++;
            if(index > liList.length - 1) {
                index = 0
            }
            for(var i = 0; i < liList.length; i++){
                if(i == index){
                    animationAll(liList[i],{opacity:1})
                }else {
                    animationAll(liList[i],{opacity:0})
                }
            }
        }
        //点击左箭头,切换画面
        left.onclick = function(){
            index--;
            if(index < 0) {
                index = liList.length - 1;
            }
            for(var i = 0; i < liList.length; i++){
                if(i == index){
                    animationAll(liList[i],{opacity:1})
                }else {
                    animationAll(liList[i],{opacity:0})
                }
            }
        }
    }(window))        
</script>
<script src='../jquery-1.12.4.js'></script>
<script>
    // $(function(){
    //     $('.box').on('mouseenter',function(){
    //         $('.arr').show();
    //     }).on('mouseleave',function(){
    //         $('.arr').hide();
    //     })
    //     var index = 0 //记录当前在第几张
    //     $('.right').on('click',function(){
    //         index++;
    //         if(index > $('li').length-1){
    //             index = 0;
    //         }
    //         $('li').eq(index).fadeIn().siblings().fadeOut();
    //     })
    //     $('.left').on('click',function(){
    //         index--;
    //         if(index < 0){
    //             index = $('li').length-1;
    //         }
    //         $('li').eq(index).fadeIn().siblings().fadeOut();
    //     })
    // })
</script>
</html>